package com.db;

import java.sql.*;

public class DBManager {
	static Connection con;

	static String driver = "com.mysql.jdbc.Driver";

	static String user = "root";

	static String pwd = "qiuguo5400";

	static String url = "jdbc:mysql://localhost:3306/room";   //数据库的类型以及端口

	public static Connection getCon() {                  //getcon()是跟数据库建立链接的方法
		try {
			Class.forName(driver);
			con = DriverManager.getConnection(url, user, pwd);
		} catch (Exception e) {            
			e.printStackTrace();                   //printStackTrace()是在控制台打印异常信息在程序中出错的位置及原因
		}
		return con;
	}

	public static void closeCon(Connection con) {
		try {
			if (con != null || !con.isClosed()) {
				con.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		;
	}
}
